package demoMod.gdxform.core;

import com.badlogic.gdx.Gdx;

import java.util.function.Function;

public class AbstractAction {
    private Function<Float, Boolean> body;
    private float duration;

    public final boolean update() {
        duration -= Gdx.graphics.getDeltaTime();
        return body.apply(duration);
    }

    public void setBody(Function<Float, Boolean> body) {
        this.body = body;
    }

    public void setDuration(float duration) {
        this.duration = duration;
    }

    public static class Builder {
        private float duration;
        private Function<Float, Boolean> body;

        public Builder setDuration(float duration) {
            this.duration = duration;
            return this;
        }

        public Builder setActionBody(Function<Float, Boolean> body) {
            this.body = body;
            return this;
        }

        public AbstractAction build() {
            AbstractAction action = new AbstractAction();
            action.setDuration(this.duration);
            action.setBody(this.body);
            return action;
        }
    }
}
